Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
Trying to update attribute result in mass-update [Laravel 5]

I'm trying to change a value in my DB for a single item, I use first() to get an item, but for some reason when I try this function, every entry with the same primary key has the authenticated user gets the attribute 'AreFriend' updated at 1, why?

public function acceptrequest($id)
{
     $user = app('Dingo\Api\Auth\Auth')->user();
     if (!$targetuser = User::find($id)) {
         return response()->json(['status' => "The requested resource does not exists!"], 403);
     }
     if ($relation = $user->requestspending()->where('user_id', $targetuser->user_id)->first()) {
         Friend::unguard();
         $relation->AreFriend = 1;
         $relation->save();
         Friend::unguard();
         Friend::reguard();
         return response()->json(['status' => "Request accepted!"], 200);
     } else {
            return response()->json(['status' => "You do not have an invitation from this user!"], 403);
     }
}

In my database, relations with the $user id are updated. The variable $relation is an item, not a collection.

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda